package utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 * @author mi
 * 工具类读本地文件
 */
public class Read {
    public String path;

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public static String txt2String(File file){
        StringBuilder result = new StringBuilder();
        try{
            /**
             *构造一个BufferedReader类来读取文件
             */
            BufferedReader br = new BufferedReader(new FileReader(file));
            String s = null;
            /**
             *使用readLine方法，一次读一行
             */
            while((s = br.readLine())!=null){
                result.append(System.lineSeparator()+s);
            }
            br.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result.toString();
    }
    public void read(String path){
        File file1 = new File("path");
        System.out.println(txt2String(file1));
    }
}
